package com.app.business.show;

import com.app.business.model.AzProject;
import com.app.business.model.House;
import com.app.business.service.*;
import com.app.system.permission.service.DataDictService;
import com.app.system.utils.ParamUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 大屏公示（没有权限限制）
 * Created by ddz on 2022/10/17.
 */
@Controller
@RequestMapping("/showForApp/*")
@SuppressWarnings("all")
public class ShowForApp {
    @Autowired
    private ContractService contractService;
    @Autowired
    private ZsProjectService zsProjectService;
    @Autowired
    private AzProjectService azProjectService;
    @Autowired
    private DataDictService dataDictService;
    @Autowired
    private HouseService houseService;
    @Autowired
    private CarLotService carLotService;
    @Autowired
    private StorageRoomService storageRoomService;
    @Autowired
    private StatisticsService statisticsService;
    @Autowired
    private HousePersonForPropertyService housePersonForPropertyService;


    /**
     * 大屏主界面
     */
    @RequestMapping("main")
    public void main(ModelMap modelMap) {
        List<AzProject> projects = this.azProjectService.findAll();//项目对应楼栋
        Map<String,List<String>> houseByProjectIdMap = this.housePersonForPropertyService.getHouseBuildNumByAzId();//项目对应楼栋
        Map<String,Map<String,Integer>> getMaxFloorByAzIdBuildNum = this.housePersonForPropertyService.getMaxFoolrByAzIdBuildNum();//获取
        modelMap.addAttribute("projects",projects);
        modelMap.addAttribute("houseByProjectIdMap",houseByProjectIdMap);
        modelMap.addAttribute("getMaxFloorByAzIdBuildNum",getMaxFloorByAzIdBuildNum);
    }

    /**
     *
     * 楼盘图展示 【1,2,3,5】单元
     *
     * @param request
     */
    @RequestMapping("houseBuildShow")
    public void houseBuildShow(HttpServletRequest request, ModelMap modelMap) {
        this.housePicAll(request, modelMap);
    }

    /**
     * 楼盘图展示 【1,2,3,5,6,7】单元
     *
     * @param request
     * @param modelMap
     */
    @RequestMapping("houseBuildShow7")
    public void houseBuildShow7(HttpServletRequest request,ModelMap modelMap) {
        this.housePicAll(request,modelMap);
    }

    /**
     * 湖滨二期
     */
    @RequestMapping("mainTwo")
    public void mainTwo(HttpServletRequest request, ModelMap modelMap) {
        Map<String, String> colorMap = this.dataDictService.getMapByParentNameForValue_Color("APP公示");
        modelMap.addAttribute("colorMap", colorMap);

        List<AzProject> projects = this.azProjectService.findAll();//项目对应楼栋
        Map<String,List<String>> houseByProjectIdMap = this.housePersonForPropertyService.getHouseBuildNumByAzId("8");//项目对应楼栋
        Map<String,Map<String,Integer>> getMaxFloorByAzIdBuildNum = this.housePersonForPropertyService.getMaxFoolrByAzIdBuildNum();//获取
        modelMap.addAttribute("projects",projects);
        modelMap.addAttribute("houseByProjectIdMap",houseByProjectIdMap);
        modelMap.addAttribute("getMaxFloorByAzIdBuildNum",getMaxFloorByAzIdBuildNum);

    }

    /**
     * 所有部分项目
     *
     * @param request
     */
    @RequestMapping("housePicAll")
    public void housePicAll(HttpServletRequest request, ModelMap modelMap) {
        String zsProjectIdStr = ParamUtils.getString(request, "zsProjectIdStr", "");
        Integer azProjectId = ParamUtils.getInt(request, "azProjectId", 0);
        Integer maxFloor = ParamUtils.getInt(request, "maxFloor", 0);
        Integer minFloor = ParamUtils.getInt(request, "minFloor", 0);
        String buildNum = ParamUtils.getString(request, "buildNum", "");
        String floorListStr = ParamUtils.getString(request, "floorList", "");

        List<Integer> floorList = new ArrayList<>();
        if (floorListStr != null && !floorListStr.equals("")) {
            String[] strs = floorListStr.split(",");
            for (String str : strs) {
                int i = Integer.parseInt(str);
                floorList.add(i);
            }
        }

        //通过征收项目、安置项目、楼号得到所分配的houseList
        List<House> houseList = houseService.houseListAll(zsProjectIdStr,azProjectId, buildNum, floorListStr);
/*
        List<House> houseList = houseService.houseListAllItem(azProjectId, buildNum, floorListStr);
*/
        //得到层号和当前楼层的List<House>对应的map
        Map<String, List<House>> floorHouseMap = houseService.getFloorHouseMap(houseList);
        //获取当前安置项目最高层
        Map<String, Integer> maxFloorMap = houseService.getMaxFloorAllMap(azProjectId, buildNum);

        //房源状态
        Map<String, String> colorMap = this.dataDictService.getMapByParentNameForValue_Color("APP公示");
        //房屋类型
        Map<String, String> houseHoldMap = this.dataDictService.getMapByParentNameForValue_Name("房屋户型");

        modelMap.addAttribute("buildNum", buildNum);
        modelMap.addAttribute("floorHouseMap", floorHouseMap);
        modelMap.addAttribute("maxFloor", maxFloor);
        modelMap.addAttribute("minFloor", minFloor);
        modelMap.addAttribute("colorMap", colorMap);
        modelMap.addAttribute("houseHoldMap", houseHoldMap);
    }


    /**
     * 楼盘图
     *
     * @param request
     */
    @RequestMapping("housePic")
    public void housePic(HttpServletRequest request, ModelMap modelMap) {
        String zsProjectIdStr = ParamUtils.getString(request, "zsProjectIdStr", "");
        Integer azProjectId = ParamUtils.getInt(request, "azProjectId", 0);
        Integer maxFloor = ParamUtils.getInt(request, "maxFloor", 0);
        Integer minFloor = ParamUtils.getInt(request, "minFloor", 0);
        String buildNum = ParamUtils.getString(request, "buildNum", "");
        String floorListStr = ParamUtils.getString(request, "floorList", "");
        List<Integer> floorList = new ArrayList<>();
        if (floorListStr != null && !floorListStr.equals("")) {
            String[] strs = floorListStr.split(",");
            for (String str : strs) {
                int i = Integer.parseInt(str);
                floorList.add(i);
            }
        }

        //通过征收项目、安置项目、楼号得到所分配的houseList
        List<House> houseList = houseService.houseList(zsProjectIdStr, azProjectId, buildNum, floorListStr);
        //得到层号和当前楼层的List<House>对应的map
        Map<String, List<House>> floorHouseMap = houseService.getFloorHouseMap(houseList);
        //获取当前安置项目最高层
        Map<String, Integer> maxFloorMap = houseService.getMaxFloorMap(zsProjectIdStr, azProjectId, buildNum);

        //房源状态
        Map<String, String> colorMap = this.dataDictService.getMapByParentNameForValue_Color("公示颜色");
        //房屋类型
        Map<String, String> houseHoldMap = this.dataDictService.getMapByParentNameForValue_Name("房屋户型");

        modelMap.addAttribute("buildNum", buildNum);
        modelMap.addAttribute("floorHouseMap", floorHouseMap);
        modelMap.addAttribute("maxFloor", maxFloor);
        modelMap.addAttribute("minFloor", minFloor);
        modelMap.addAttribute("colorMap", colorMap);
        modelMap.addAttribute("houseHoldMap", houseHoldMap);
    }
}
